package com.spica.spicaschool.ui.mydiary

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.spica.spicaschool.base.BaseFragment
import com.spica.spicaschool.databinding.FragmentMyDiaryBinding

/**
 * 我的发布内容列表
 */
class MyDiaryFragment : BaseFragment<FragmentMyDiaryBinding>() {


    private val title = arrayListOf("公开日记", "私密日记")

    /**
     * 初始化
     */
    override fun init() {
        viewBinding.viewpager.adapter = FragmentAdapter(this)
        TabLayoutMediator(viewBinding.tablayout, viewBinding.viewpager) { tab, position ->
            run {
                tab.text = title[position]
            }
        }.attach()
    }

    override fun setupViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentMyDiaryBinding = FragmentMyDiaryBinding.inflate(inflater, container, false)


    private class FragmentAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
        override fun getItemCount(): Int = 2
        override fun createFragment(position: Int): Fragment {
            return MyDiariesFragment.newInstance(position)
        }
    }

}